package edu.uc.persistence;

import android.util.Log;
import edu.uc.dto.User;

/**
 * This is the master login checker which checks to see if a user is logged in.
 * Buttons throughout the application will be displayed accordingly.
 * 
 * @author Rozzly
 *
 */
public class LoginDAO implements LoginDAOInterface{
	
	@Override
	public User isLoggedIn(User SessionUser) throws Exception {

		if (SessionUser.getEmail().equals(""))
		{
			// Set user guest to default display values
			SessionUser.setUserId("");
			SessionUser.setFirstName("Guest");
			SessionUser.setLastName("");
			SessionUser.setEmail("");
			SessionUser.setPassword("");
			
			// State user is not logged on
			Log.i(getClass().getName(), "User is not logged in. Defaulting to 'GUEST'.");
			
			// Return the SessionUser object with "Guest" values
			return SessionUser;
		}		
		else 
		{
			// Set the SessionUser object with "Logged in user" values
			SessionUser.getUserId();
			SessionUser.getFirstName();
			SessionUser.getLastName();
			SessionUser.getEmail();
			SessionUser.getPassword();
			
			// State user is logged in
			Log.i(getClass().getName(), "User is logged in as: " + SessionUser.getFirstName());
			
			// Return the SessionUser as "Logged in" user
			return SessionUser;
			
		}

	}
	
}
